import axios from "axios"
import Assert from "../utils/shf/Assert";
export default class ReqEasyMedia {
    private static _instance:ReqEasyMedia ;
    public static use(){
        if(!this._instance){
            this._instance = new ReqEasyMedia();
            this._instance.reqUrl = window["reqMonitorUrl"];
        }
        return this._instance;
    }
    public reqUrl:string = "";
    public async getList(){
        let res = await axios.get(this.reqUrl+"/list",{withCredentials:false});
        return this.dealRes(res);
    }
    public async edit(params){
        let res = await axios.get(this.reqUrl+"/edit",{withCredentials:false,params});
        return this.dealRes(res);
    }
    public async add(params){
        let res = await axios.get(this.reqUrl+"/add",{withCredentials:false,params});
        return this.dealRes(res);
    }
    public async del(params){
        let res = await axios.get(this.reqUrl+"/del",{withCredentials:false,params});
        return this.dealRes(res);
    }
    private dealRes(res:any){
        if(res&&res.data&&res.data.code==200)
        {
            return Promise.resolve(res.data.data);
        }
        if(res&&res.data&&res.data.msg)
        {
            Assert.isFalse(true,res.data.msg);
            return Promise.resolve();
        }
        Assert.isFalse(true,"请求失败");
        return Promise.resolve();
    }

}